﻿/**
 * Created by Administrator on 2017/9/6.
 *公客转私客
 */
define(['api'],function (api){
    var ShiftCustomerToStaff = {
        name: 'shift-customer-to-staff',
        template: ''
        + '<Modal title="转为个人客户"'
        + '       v-model="showShiftCustomerToStaff"'
        + '       width="360"'
        + '       ok-text="确认"'
        + '       v-on:on-cancel="closeShift"'
        + '       v-on:on-ok="shiftCustomerToStaff"'
        + '       v-bind:closable="false"'
        + '       v-bind:mask-closable="false"'
        + '       class-name="turnClientWrap  vertical-center-modal shift-customer-to-other-staff">'
        + '<div class="modal-content">'
        + ' <ul class="pri-ul">'
        + ' <li class="pri-li">'
        + '     <span class="model-left removeLeft">选择销售员</span>'
        + '     <p class="model-right remove-right">'
        + '         <i-select v-model="shiftInfo.newStaffId">'
        + '             <i-option v-for="item in nodeOption" :value="item.value" :key="item.label">{{item.label}}</i-option>'
        + ' 		</i-select>'
        + ' 	</p>'
        + ' </li >'
        + '    <li class="pri-li">'
        + '         <span class="model-left removeLeft">清空回访记录</span>'
        + '         <p class="model-right remove-right">'
        + '             <Radio-group v-model="shiftInfo.isClearVisit">'
        + '                 <Radio label="true"><span>是</span></Radio>'
        + '                 <Radio label="false"><span>否</span></Radio>'
        + '             </Radio-group>'
        + '         </p>'
        + '     </li>'
        + '  </ul>'
        + '</div >'
        + '</Modal>',
        props: {
            type: String,
            status: String
        },
        data: function () {
            return {
                nodeOption: [],
                shiftInfo: {
                    newStaffId: "",
                    isClearVisit: "false",
                    customerIdList: [],
                },
                showShiftCustomerToStaff: false,
            }
        },
        methods: {
            closeShift: function () {
            },
            shiftCustomerToStaff() {
                var thisShift = this;
                api.Post_Shift_Customer_ToStaff(thisShift.shiftInfo)
                    .done(function (data) {
                        if (data.IsSuccess) {
                            thisShift.$Message.success('转移成功');
                            //触发shiftCustomerToStaffSuccess
                            window.bus.$emit("shiftCustomerToStaffSuccess");
                        } else {
                            thisShift.$Message.error(data.ErrMsg);
                        }
                    })
                    .fail(function () {
                        thisShift.$Message.error('转移失败');
                    });
            },
        },
        mounted: function () {
            var thisShift = this;
            //监听showShiftCustomerToStaff
            window.bus.$on("showShiftCustomerToStaff", function (data) {
                thisShift.shiftInfo.customerIdList = data;
                thisShift.showShiftCustomerToStaff = true;
                //触发deleteFocus
                window.bus.$emit("deleteFocus");
            });
            api.Get_Staff_By_CompanyId({companyId: localStorage.companyId})
                .done(function (data) {
                    if (data.IsSuccess) {
                        thisShift.nodeOption = data.ResultObject;
                    } else {
                        thisShift.$Message.error(data.ErrMsg);
                    }
                })
                .fail(function () {
                    thisShift.$Message.error('查询出错');
                });
        },
    };
    return ShiftCustomerToStaff;
});
